from rest_framework.generics import ListAPIView, CreateAPIView

from sadmin.serializersss.users_serializers import UserSerializer
from sadmin.utils import Mypage
from users.models import User

# TODO CreateAPIView方法新建用户后，密码是明文的
class UserView(ListAPIView,CreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    pagination_class = Mypage
    # TODO 重写了get_queryset 方法，此方法返回的是一个查询集。
    def get_queryset(self):
        keyword = self.request.query_params.get("keyword")
        if keyword:
            return self.queryset.filter(username__contains=keyword)
        return self.queryset.all()